<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
	<html>

	<head>
		<meta charset="utf-8">
		<title>注册</title>
		<link href="css/myui.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/mui.min.css">
		<link rel="stylesheet" href="css/myui.css">
		<style type="text/css">
			html,body{
				background: #fcfcfc;
			}
			.register_code{
				width: 33% !important;
				font-size: 0.9rem !important;
				background: #53b0ff !important;
				color: #fff !important;
				border: 0 !important;
				margin-top: 0.3rem !important;
    			padding: 0.3rem 0rem !important;
    			line-height: inherit !important;
			}
			.mui-input-row label~input{
			    width: 80%;
			    float: left;
			    line-height: 40px;
			    padding: 11px 10px;
			}
			#tel{
			    height: auto;
			    line-height: inherit;
			}
		</style>
		<script src="js/mui.min.js"></script>
		<script src="js/index.js"></script>
		<script src="js/jquery-1.9.0.js"></script>
		<script type="text/javascript" charset="utf-8">
			mui.init();
			mui.plusReady(function(){
				var tel = document.getElementById("tel");
				var code = document.getElementById("code");
				var register_code = document.getElementById("register_code");
				var password = document.getElementById("password");
				var reg = document.getElementById("reg");
				//存储值
				var istrue;
				var isphoneNum;
				//自动验证手机是否被注册了
				$('input[name="phone_num"]').blur(function(){
		            if($(this).val()!=''){
		                var phoneNum = $(this).val();
		                var url = get_url()+'register/lawyer/checkPhone/'+phoneNum;
		                $.ajax({
							type: "post",
							dataType: "json",
							url: url,
							data: {},
							success: function(json){
						   		if(!json){
							   		mui.toast("该用户已经被注册！！");
							   		//设置不可在发送短信
			        				register_code.value="用户已存在"; 
			        				register_code.disabled = true; 
			        				register_code.removeEventListener("tap",function(){});
							   	}else{
							   		mui.toast("该用户可以注册！！");
			        				register_code.disabled = false; 
			        				register_code.value="获取验证码"; 
									istrue = json;
		               				isphoneNum = phoneNum;
									return;
							   	}
							},
							error: function(jqXHR, textStatus, errorThrown) {
							   	alert("错误提示!!");
							}
						});
		            }else{
		                //alert("用户名不能为空！");
		                return;
		            }                     
		        }); 
				$('input[name="phone_code"]').blur(function(){
		            if($(this).val()!=''){
		            	var code = $(this).val();
		                var url = get_url()+'register/lawyer/verify/'+isphoneNum+'/'+code;
		                $.ajax({
							type: "post",
							dataType: "html",
							url: url,
							data: {},
							success: function(result){
								if(result){
							   		plus.ui.toast("验证码输入正确");
								}
							},
							error: function(jqXHR, textStatus, errorThrown) {
							   	alert("错误提示!!");
							}
						});
					}else{
						plus.ui.toast("验证码输入错误");
					}
				});
				//注册
				reg.addEventListener("tap",function(){
					if(tel.value.length == 0){
						plus.ui.toast("手机号不能为空");
						tel.focus();
						return;
					}
					if(code.value.length == 0){
						plus.ui.toast("验证码不能为空");
						code.focus();
						return;
					}
					if(password.value.length == 0){
						plus.ui.toast("密码不能为空");
						password.focus();
						return;
					}
					var phoneNum = $('input[name="phone_num"]').val();
					var RegURL = get_url()+"register/lawyer/confirm/"+phoneNum;
					mui.ajax(RegURL,{
						data:{
							password:password.value
						},
						dataType:'JSON',
						type:'POST',
						success:function(data){
							if(data){
								plus.ui.toast("注册成功");
								mui.plusReady(function(){
								  	plus.storage.setItem("phoneNum", phoneNum);
		    					});
								mui.openWindow({
								  url: "login.html", 
								  id:"login"
								});
							}else{
								plus.ui.toast("注册失败");
							}
						},
						error:function(){
							//plus.ui.toast("注册失败");
						}
					});
				});
				//打开登录页面
				localtionURL("login","login.html");
				//获取验证码
				if(!istrue){
					var CODE_This;
					register_code.addEventListener("tap",function(){
						var CODE_This = this;
						if(tel.value.length == 11){
							var TelValue = tel.value;
							var CodeUrl = get_url()+"register/lawyer/sendCode/"+TelValue;
							mui.ajax(CodeUrl,{
								data:{},
								dataType:'JSON',
								type:'POST',
								timeout:10000,
								success:function(result){
									plus.ui.toast("获取验证码成功");
									settime(CODE_This);
								},
								error:function(){
									//plus.ui.toast("手机号码已存在");
								}
							});
						}else{
							plus.ui.toast("手机号输入有误");
						}
					});
				}
			});
			var countdown=60; 
			function settime(obj) { 
			    if (countdown == 0) { 
			        obj.removeAttribute("disabled");    
			        obj.value="获取验证码"; 
			        countdown = 60; 
			        return;
			    } else { 
			        obj.setAttribute("disabled", true); 
			        obj.value="重新发送(" + countdown + ")"; 
			        countdown--; 
			    } 
			setTimeout(function() { 
			    settime(obj) }
			    ,1000) 
			}
		</script>
	</head>

	<body>

		<div id="app" class="mui-views" data-view="1">
			<div class="mui-view">
				<div class="mui-navbar">
					<div class="mui-navbar-inner mui-bar mui-bar-nav mui-navbar-center">
						<button type="button" class="mui-left mui-action-back mui-btn  mui-btn-link mui-btn-nav mui-pull-left mui-pull-left_style">
							<span class="mui-icon mui-icon-left-nav"></span>
						</button>
						<h1 class="mui-center mui-title mui-title_fff" style="margin-left: -15px;">注册</h1>
					</div>
				</div>
				<div class="mui-pages">
					<div id="setting" class="mui-page mui-page-center">
			<!--页面主内容区结束-->
					</div>
				</div>
			</div>
		</div>

		<div class="login_content">
			<div class="login_content1">
				<div class="mui-input-row">
					<label><img src="img/login_user.png"></label>
					<input type="tel" placeholder="请输入手机号" id="tel" name="phone_num">
				</div>
			</div>
			<div class="login_content1">
				<div class="mui-input-row">
					<label><img src="img/Mail.png"></label>
					<input type="text" placeholder="请输入验证码" style="width: 50%;float: left;" id="code" name="phone_code">
					<input type="button" class="register_code" id="register_code" value="获取验证码" /> 
				</div>
			</div>
			<div class="login_content1">
				<div class="mui-input-row">
					<label><img src="img/login_key.png"></label>
					<input type="password" placeholder="请输入6-12位密码" id="password">
				</div>
			</div>
			<div class="login_content1_btn" id="reg">
				<button>注册</button>
			</div>
			<div class="login_content1_existence">
				<button id="login">已有账号直接登陆</button>
			</div>
		</div>
				
		
	</body>

	</html>